﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ISHotelApp.Database;

namespace ISHotel_WinForm
{
    public partial class StravovaniForm : Form
    {
        public StravovaniForm()
        {
            InitializeComponent();
            StravovaniTable stravovaniTable = new StravovaniTable();
            dataGridViewStravovani.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn idStravovaniColumn = new DataGridViewTextBoxColumn();
            idStravovaniColumn.DataPropertyName = "id_stravovani";
            idStravovaniColumn.HeaderText = "ID Stravovani";

            DataGridViewTextBoxColumn nazevStravovaniColumn = new DataGridViewTextBoxColumn();
            nazevStravovaniColumn.DataPropertyName = "nazev_stravovani";
            nazevStravovaniColumn.HeaderText = "Nazev stravovani";

            DataGridViewTextBoxColumn cenaStravovaniColumn = new DataGridViewTextBoxColumn();
            cenaStravovaniColumn.DataPropertyName = "cena_stravovani";
            cenaStravovaniColumn.HeaderText = "Cena stravovani";

            dataGridViewStravovani.DataSource = stravovaniTable.Select();

            dataGridViewStravovani.Columns.Add(idStravovaniColumn);
            dataGridViewStravovani.Columns.Add(nazevStravovaniColumn);
            dataGridViewStravovani.Columns.Add(cenaStravovaniColumn);
        }

        private void dataGridViewStravovani_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            ErrLabel.Text = "";
            if (e.RowIndex >= 0)
            {
                int id_stravovani = (int)dataGridViewStravovani.Rows[e.RowIndex].Cells[0].Value;
                StravovaniTable stravovaniTable = new StravovaniTable();
                Stravovani stravovani = stravovaniTable.Select(id_stravovani);
                IDStravovaniTB.Text = stravovani.id_stravovani.ToString();
                NazevStravovaniTB.Text = stravovani.nazev_stravovani;
                CenaStravovaniTB.Text = stravovani.cena_stravovani.ToString();
            }
        }
    }
}
